package com.ruoyi.asset.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AstManual;
import com.ruoyi.asset.service.IAstManualService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 说明书Controller
 * 
 * @author xunzhe
 * @date 2024-06-26
 */
@Controller
@RequestMapping("/asset/astManual")
public class AstManualController extends BaseController
{
    private String prefix = "asset/astManual";

    @Autowired
    private IAstManualService astManualService;

    @RequiresPermissions("asset:astManual:view")
    @GetMapping()
    public String astManual()
    {
        return prefix + "/astManual";
    }

    /**
     * 查询说明书列表
     */
    @RequiresPermissions("asset:astManual:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AstManual astManual)
    {
        startPage();
        List<AstManual> list = astManualService.selectAstManualList(astManual);
        return getDataTable(list);
    }

    /**
     * 导出说明书列表
     */
    @RequiresPermissions("asset:astManual:export")
    @Log(title = "说明书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AstManual astManual)
    {
        List<AstManual> list = astManualService.selectAstManualList(astManual);
        ExcelUtil<AstManual> util = new ExcelUtil<AstManual>(AstManual.class);
        return util.exportExcel(list, "说明书数据");
    }

    /**
     * 新增说明书
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存说明书
     */
    @RequiresPermissions("asset:astManual:add")
    @Log(title = "说明书", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AstManual astManual)
    {
        return toAjax(astManualService.insertAstManual(astManual));
    }

    /**
     * 修改说明书
     */
    @RequiresPermissions("asset:astManual:edit")
    @GetMapping("/edit/{manualId}")
    public String edit(@PathVariable("manualId") Long manualId, ModelMap mmap)
    {
        AstManual astManual = astManualService.selectAstManualByManualId(manualId);
        mmap.put("astManual", astManual);
        return prefix + "/edit";
    }

    /**
     * 修改保存说明书
     */
    @RequiresPermissions("asset:astManual:edit")
    @Log(title = "说明书", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AstManual astManual)
    {
        return toAjax(astManualService.updateAstManual(astManual));
    }

    /**
     * 删除说明书
     */
    @RequiresPermissions("asset:astManual:remove")
    @Log(title = "说明书", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(astManualService.deleteAstManualByManualIds(ids));
    }
}
